<?php
class IndexAction extends CommonAction {
	// 框架首页
	public function index() {
		//C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		//C ( 'SHOW_PAGE_TRACE', false );
		$news = D('News');
		$list = $news->where('status = 1')->order('id desc')->limit(15)->select();
		$this->assign('newslist',$list);
		$this->display();
	}
	
	public function insert(){
		$news = D('News');
		$news->create();
		if($news->add()){
			$this->ajaxReturn(1,'添加成功！',true);	
		}else{
			$this->ajaxReturn(0,'添加失败！',0);
		}
	}
	public function myGetField(){
        $model 	= D('News');
		$id		= $_POST['id'];
		$f		= $_POST['f'];
		$ff		= $model->where('id='.$id)->getField($f);
		if($ff){
			$this->ajaxReturn($ff,"查询成功！",1); 
		}else{  
		  	$this->ajaxReturn('无信息',"没有相关信息！",0); 
		}
	}
	public function delete(){
		$id		= $_GET['id'];
		$news 	= D('News');
		if($news->delete($id)){
			$this->ajaxReturn("删除成功！","删除成功！",1); 
		}else{  
		  	$this->ajaxReturn('删除失败！',"删除失败！",0); 
		}	
	}
	public function update(){
		$news = D('News');
		$data['title']		= $_POST['title'];
		$data['content']	= $_POST['content'];
		$flag = $news->where('id='.$_POST['id'])->data($data)->save();
		if($flag){
			$this->ajaxReturn("编辑成功！","编辑成功！",1); 
		}else{  
		  	$this->ajaxReturn('编辑失败！',"编辑失败！",0); 
		}	
	}
}
?>